package com.topboya.linker.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.topboya.linker.R;
import com.topboya.linker.model.response.MyNoticeListResponse;
import com.topboya.linker.utils.AndroidUtils;

import java.util.List;

public class NotifyAdapter extends RecyclerView.Adapter<NotifyAdapter.ListItemViewHolder>{

      private static final String TAG="NotifyAdapter:";
      private Context mContext;
      private List<MyNoticeListResponse.MsgList> msgLists;

      public NotifyAdapter(Context mContext,List<MyNoticeListResponse.MsgList> msgLists ){

        this.msgLists=msgLists;
        this.mContext=mContext;
        }

        @Override
        public ListItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i){

        View itemView=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.notify_item,viewGroup,false);

        return new ListItemViewHolder(itemView);

        }


       //绑定界面，设置监听
       @Override
       public void onBindViewHolder(final ListItemViewHolder holder,final int position){

        holder.tv_notify_title.setText(msgLists.get(position).getTitle());
        holder.tv_notify_time.setText(AndroidUtils.getNotifyTime(msgLists.get(position).getUpdateDate()));
        if (null !=msgLists.get(position).getReadStatus() && Integer.valueOf(msgLists.get(position).getReadStatus()) ==0){

            holder.tv_notify_circle.setVisibility(View.VISIBLE);

        }else {

            holder.tv_notify_circle.setVisibility(View.GONE);
        }

        holder.itemView.setOnClickListener(v1->{

            if(null!=itemClickListener) itemClickListener.onClick(holder.itemView,position);

        });
       }

       @Override
       public int getItemCount(){

        return msgLists==null?0:msgLists.size();

        }

     public class ListItemViewHolder extends RecyclerView.ViewHolder {

       //ViewHolder
       TextView tv_notify_title;
       TextView tv_notify_circle;
       TextView tv_notify_time;

    ListItemViewHolder(View view) {

        super(view);
        this.tv_notify_title = view.findViewById(R.id.tv_notify_title);
        this.tv_notify_circle = view.findViewById(R.id.tv_notify_circle);
        this.tv_notify_time = view.findViewById(R.id.tv_notify_time);

    }

}
    private OnItemClickListener itemClickListener;

    public void setOnItemClickListener(OnItemClickListener itemClickListener) {

        this.itemClickListener = itemClickListener;
    }

    public interface OnItemClickListener {

    void onClick(View v, int position);

}
}